<template>
  <div class="login-container">
    <div class="logincont">
      <Form v-model="login">
        <FormItem label="用户名：">
          <Input type="text" v-model="login.username" size="large" />
        </FormItem>
        <FormItem label="密码：">
          <Input type="password" v-model="login.userpwd" size="large" />
        </FormItem>
        <FormItem>
          <Button type="primary" long size="large" @click="handleLogin">登陆</Button>
        </FormItem>
      </Form>
    </div>
  </div>
</template>

<script>
export default {
  middleware: 'notauth',
  layout: 'login',
  data() {
    return {
      login: {
        username: '',
        userpwd: ''
      }
    }
  },
  methods: {
    handleLogin() {
      this.$axios.post('/adminapi/userlogin', {
        username: this.login.username,
        userpwd: this.login.userpwd
      }).then(res => {
        if (res.data.code == 200) {
          this.$Message.success('登陆成功！')
          this.$router.push('/admin')
        } else {
          this.$Message.error(res.data.message)
        }
      }).catch(err => {
        this.$Message.error('网络错误稍后重试！')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.logincont {
  width: 300px;

}
</style>
